package hn.sigit.logic.queries.impl;

import hn.sigit.logic.queries.QueryHelper;

import java.io.Serializable;
import java.util.List;

public abstract class QueryHelperImpl<T> implements Serializable, QueryHelper<T> {
	private static final long serialVersionUID = 1L;
	
	private String searchSelector = "0";
	private String searchText;
	
	protected List<T> queryResultList;
	protected T selected;
	
	
	@Override
	public String getSearchSelector() {
		return searchSelector;
	}
	@Override
	public void setSearchSelector(String searchSelector) {
		this.searchSelector = searchSelector;
	}
	
	@Override
	public String getSearchText() {
		return searchText;
	}
	@Override
	public void setSearchText(String searchText) {
		this.searchText = searchText;
	}

	
	@Override
	public abstract List<T> getQueryResultList();
	@Override
	public void setQueryResultList(List<T> queryResultList) {
		this.queryResultList = queryResultList;
	}
	
	
	@Override
	public abstract T getSelected();
	@Override
	public abstract void setSelected(T selected);
	
	
	@Override
	public String doNewSearch() {
		setQueryResultList(null);
		setSelected(null);
		
		List<T> queryResult = getQueryResultList();
		if (queryResult != null && queryResult.size() > 1)
			return "transactionSearchResult.xhtml";
		else if (queryResult.size() == 1)
			setSelected(queryResult.get(0));
		
		return null;
	}
}
